/*
 * =====================================================================================
 *
 *       Filename:  inter.hpp
 *
 *    Description: Interpolation
 *
 *        Version:  1.0
 *        Created:  10/28/2012 08:22:27 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Sergey Gvozdarev,
 *   Organization:  MIPT 016
 *
 * =====================================================================================
 */
#include "definitions.hpp"

namespace INTER
{

    Matrix D;
    int N;

    inline real_t l( int i, real_t x)
    {
        real_t res = 1.0;
        for ( int j = 0; j < N; j++)
        {
            if ( i == j)
            {
                continue;
            }
            real_t tmp =( x - D( j, 0)) / ( D( i, 0) - D( j, 0));

            res *= tmp;

        }

        std::cout << res << std::endl;

        return res;
    }

    inline real_t L( real_t x)
    {
        real_t res = 0.0;
        for ( int i = 0; i < N; i++)
        {
            res += D( i, 1) * l( i, x);
        }
        return res;
    }

    inline real_t F( real_t x, real_t x1, real_t y1, real_t x2,real_t y2,real_t x3,real_t y3)
    {
        N = 3;

        D.resize( 3, 2, false);

        D( 0,0) = x1;
        D( 0,1) = y1;

        D( 1,0) = x2;
        D( 1,1) = y2;

        D( 2,0) = x3;
        D( 2,1) = y3;

        return L( x);
    }

} //end namespace INTER
